<template>
  <div class="app-container" v-loading="pageLoading">
    <el-button type="primary" class="fr" @click="createItem" v-permission="'custom.add'">创建</el-button>
    <div class="filter-container">
      <el-input style="width: 300px" placeholder="输入查询条件按回车" clearable prefix-icon="el-icon-search" class="filter-item"
        @keyup.enter.native="research" @clear="research" v-model="query.queryString"></el-input>
      <el-button class="filter-item" type="success" plain @click="research">查询</el-button>
      <el-button class="filter-item" type="info" plain @click="exportData" :loading="exportLoading">导出 </el-button>
    </div>
    <z-table :list="list" :tableProps="tableProps" :columns="columns" @editItem="editItem" @deleteItem="deleteItem">
    </z-table>
    <z-pagination :pagination="pagination" :total="total" :page.sync="query.page" :limit.sync="query.size"
      @change="getList"></z-pagination>
    <z-form-dialog :name="name" :data="data" :formProps="formProps" :fields="fields" @submit="submit"
      :submitLoading="submitLoading" :visible.sync="editFormVisible"></z-form-dialog>
  </div>
</template>

<script>
import commonMixin from '@/views/_common/mixin'
export default {
  mixins: [commonMixin],
  name: 'custom',
  data: function () {
    return {
      api: this.$api.custom,
      apiEdit: this.$api.custom + 'add',
      name: '客户类型',
      columns: [
        // { title: '客户类型编码', key: 'cust_type_code', width: 130 },
        { title: '客户类型', key: 'cust_type', width: 130 },
        { title: '客户编码', key: 'cust_code', width: 100 },
        { title: '客户名称', key: 'cust_name' },
        { title: '备注', key: 'remarks', width: 120 },
        { title: '修改人', key: 'modify_user', width: 100 },
        { title: '最后修改', key: 'modify_time', width: 140 },
      ],
      fields: [
        // {
        //   title: '客户类型编码',
        //   key: 'cust_type_code',
        //   span: 12,
        //   required: true,
        // },
        {
          title: '客户类型',
          key: 'cust_type',
          span: 12,
          name: 'select',
          options: [],
          required: true,
        },
        {
          title: '客户编码',
          key: 'cust_code',
          span: 12,
          props: {},
          required: true,
        },
        {
          title: '客户名称',
          key: 'cust_name',
          span: 12,
          required: true,
        },
        { title: '客户全称', key: 'cust_full_name', span: 12 },
        { title: '地址（中文）', key: 'address_cn', span: 24 },
        { title: '地址（英文）', key: 'address_en', span: 24 },
        { title: '备注', key: 'remarks', span: 24 },
      ],
      initData: {
        tel_no: '',
        e_mail: '',
        contact: '',
        principal: '',
        sales: '',
        fax_no: '',
        country: '',
        area: '',
        address2: '',
        erp_create_date: '',
        erp_modify_date: '',
      },
    }
  },
  methods: {},
  created: function () {
    this.getList()
    this.$request(this.$api.dictionary + 'getdirectchildren', {
      parentType: 'customer_type',
    }).then((r) => {
      this.getFieldConfig('cust_type').options = this.arrayOptions(r, 'value', 'label')
    })
  },
  watch: {
    data: function (val) {
      this.getFieldConfig('cust_code').props.disabled = val.id ? true : false
    },
  },
}
</script>
<style scoped>
</style>
